package org.example.spring_boot_blog.controller;

import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.example.spring_boot_blog.common.pojo.request.UserLoginParam;
import org.example.spring_boot_blog.common.pojo.response.UserInfoResponse;
import org.example.spring_boot_blog.common.pojo.response.UserLoginResponse;
import org.example.spring_boot_blog.service.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;
    @PostMapping("/login")
    public UserLoginResponse login(@Validated @RequestBody UserLoginParam userParam){
        log.info("用户登录,userName:{}",userParam.getUserName());
        return userService.login(userParam);
    }

    @GetMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull Integer userId) {
        log.info("获取用户信息,userId:{}",userId);
        return userService.getUserInfoById(userId);
    }
    @GetMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull Integer blogId) {
        log.info("获取作者信息,blogId:{}",blogId);
        return userService.getAuthorInfoById(blogId);
    }
}
